package at.fhj.swd.pse.controller;




import javax.annotation.PostConstruct;
import javax.enterprise.inject.Model;
import javax.faces.bean.ManagedBean;
import javax.inject.Inject;
import javax.inject.Named;

import org.jboss.logging.Logger;
import org.primefaces.event.FileUploadEvent;
import org.primefaces.model.UploadedFile;

import at.fhj.swd.pse.beans.UserBean;

@Model
@ManagedBean(name = "fileUploadController", eager = true)
public class FileUploadController {

	private static final Logger logger = Logger
			.getLogger(FileUploadController.class);

	@Inject
	private UserBean userBean;
	
	@Named
	private UploadedFile uploadedFile;
	
	@Named 
	private byte[] image;

	@PostConstruct
	public void init() {
		logger.info("init FileUploadController");

	}

	public void uploadUserProfileImage(FileUploadEvent event) {
		byte[] image = event.getFile().getContents();
		userBean.uploadUserProfileImage(image);
	}
	
	  public UploadedFile getFile()
	  {
	    return uploadedFile; 
	  }

	  public void setFile(UploadedFile file)
	  {
	    this.uploadedFile = file; 
	  }
}